<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use app\common\lib\Data;
class Common extends Controller {
	
	protected $data;
	
	protected function initialize()
    {			
				$config = db('config')->cache('config',0,'config')->column('*','name');
				$this->getCategory();
				if(isMobile()){
					config('template.default_them','wap');
				}else{
					config('template.default_them','index');
				}
				$data = request()->param();
				$aid = isset($data['aid'])?$data['aid']:"";
				$cid = isset($data['cid'])?$data['cid']:"";
				$page = isset($data['page'])?$data['page']:1;
				$this->assign('cid',$cid);
				$this->assign('aid',$aid);
				$this->assign('page',$page);
				$this->assign('config',$config);
    }
	
	public function getCategory(){
		$data = db('category')->order('sort')->select();
		$dataTree = new Data;
		foreach($data as $k=>$v){
			if($dataTree->hasChild($data,$v['id'])){
				$data[$k]['hasChild'] = 1;
			}else{
				$data[$k]['hasChild'] = 0;
			}
			if($v['type'] == 1){
				$data[$k]['url'] = "lists.html?cid=".$v['id'];
			}
			if($v['type'] == 2){
				$data[$k]['url'] = "category.html?cid=".$v['id'];				   
			}
			if($v['type'] == 3){
				$data[$k]['url'] = "page.html?cid=".$v['id'];			   
			}
			if($v['type'] == 4){
				$data[$k]['url'] = $v['url']."?cid=".$v['id'];					   
			}
			if($v['type'] == 5){
				$data[$k]['url'] = $v['url'];			   
				$data[$k]['target'] = true;			   
			}
		}
		$ndata = $dataTree->channelLevel($data,0,"",'id');
		
		$this->assign('menu',$ndata);
	}
	
}